/*
 * unblockPCB.c
 *
 *  Created on: Oct 2, 2013
 *      Author: Joseph DeLong
 */

#include <stdlib.h>
#include "mpx_pcb.h"

/*
 * UNBLOCK PCB
 * Written by Joseph DeLong
 * Debugged by Alex Newcomer
 * Calls find_PCB(), places the PCB in the unblocked state and reinserts it to the correct queue if necessary
 * Parameters: name of process to block
 */
void unblockPCB(char processName[9], struct MPX_Q *r, struct MPX_Q *b) {
	struct MPX_PCB *pcb;
	pcb = findPCB(processName);
	if(pcb == NULL) { //couldn't find PCB
		printf("Couldn't find PCB %s to set to UNBLOCKED state.\n", processName);
	}
	else { //PCB found!
		if((*pcb).pcb_state != -1) { //PCB already unblocked
			printf("PCB %s is already in the UNBLOCKED state.\n", processName);
		}
		else {
			(*pcb).pcb_state = 0; //set state to UNBLOCKED
			removePCB(pcb,r,b); //remove from blocked queue
			insertPCB(pcb,r,b); //add to ready queue
			printf("PCB %s successfully UNBLOCKED.\n", processName);
		}
	}
}
